﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECI.DynamicData.ElementBuilder;
using ECI.Entities;
using System.Web.UI.WebControls;
using ECI.Controls;
using ECI.CommonLibrary;

namespace ECI.DynamicData.ElementEvent
{
    public class DropdownListEvent
    {
        private ElementParameter param;

        public DropdownListEvent(ElementParameter param)
        {
            this.param = param;
        }

        public void DropdownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            EciField field = param.Field;
            string nextDDLTraget = field.NextDdlTarget;
            string nextDDLTargetConn = field.NextDdlTargetConn;
        

            ECIDropDownList cboList = sender as ECIDropDownList;
            string value = cboList.SelectedValue;

            nextDDLTargetConn = nextDDLTargetConn.Replace("{KEY}",value);

            ECIDropDownList targetList = (ECIDropDownList)PageHelper.CurrentPage.FindControl("txt" + nextDDLTraget);
            if (targetList != null)
            {
                targetList.Items.Clear();
                targetList.BindDataAuto(nextDDLTargetConn);
            }

        }
    }
}
